﻿using System;
using System.Collections.Generic;
using System.Web;
using KYO.DAL;
using ObjectPersistence;
using Portal.API;

/// <summary>
/// Summary description for AdminUser
/// </summary>
public class AdminUser
{
    UserAssembler service = new UserAssembler();
    public AdminUser()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public bool Login(string username, string password)
    {
        bool login;
        string where = "Username = '" + username + "' AND " + "Password = '" + Crypto.Encrypt(password)+"'";

        User user = service.ReadSingle(where);
        if (user != null)
        {
            HttpContext.Current.Session["User"] = user;
            
            login = true;
        }
        else
            login = false;
        return login;
          
    }

    public void Logout()
    {

        HttpContext.Current.Session["User"] = null;
    }

    public bool IsLogin()
    {
        if (HttpContext.Current.Session["User"] == null) return false;
        return true;
    }

    public User Admin
    {
        get { return (User)HttpContext.Current.Session["User"]; }
    }

    
}
